﻿namespace RL
{
    using System;
    using System.ComponentModel;
    using System.ComponentModel.Design;

    public class AjaxPlaceHolderDesignerActionList : DesignerActionList
    {
        private RL.AjaxPlaceHolder _controlDesigner;
        private DesignerActionUIService _designerActionUISvc;

        public AjaxPlaceHolderDesignerActionList(IComponent component) : base(component)
        {
            this._designerActionUISvc = base.GetService(typeof(DesignerActionUIService)) as DesignerActionUIService;
            this._controlDesigner = component as RL.AjaxPlaceHolder;
        }

        private PropertyDescriptor GetPropertyByName(string propName)
        {
            PropertyDescriptor descriptor = TypeDescriptor.GetProperties(this._controlDesigner)[propName];
            if (null == descriptor)
            {
                throw new ArgumentException("Matching ColorLabel property not found!", propName);
            }
            return descriptor;
        }

        public override DesignerActionItemCollection GetSortedActionItems()
        {
            DesignerActionItemCollection items = new DesignerActionItemCollection();
            DesignerActionHeaderItem item = new DesignerActionHeaderItem("Files In Head");
            items.Add(item);
            DesignerActionPropertyItem item2 = new DesignerActionPropertyItem("ScriptFiles", "ScriptFiles(JS)", "Files In Head", "your javascript files to be added");
            items.Add(item2);
            DesignerActionPropertyItem item3 = new DesignerActionPropertyItem("StyleSheets", "StyleSheets(CSS)", "Files In Head", "your CSS files to be added");
            items.Add(item3);
            DesignerActionPropertyItem item4 = new DesignerActionPropertyItem("Enabled", "Enabled", "", "");
            items.Add(item4);
            return items;
        }

        public string AfterBody
        {
            get
            {
                return this._controlDesigner.AfterBody;
            }
            set
            {
                this.GetPropertyByName("AfterBody").SetValue(this._controlDesigner, value);
            }
        }

        public string AfterHeader
        {
            get
            {
                return this._controlDesigner.AfterHeader;
            }
            set
            {
                this.GetPropertyByName("AfterHeader").SetValue(this._controlDesigner, value);
            }
        }

        public string BeforeBody
        {
            get
            {
                return this._controlDesigner.BeforeBody;
            }
            set
            {
                this.GetPropertyByName("BeforeBody").SetValue(this._controlDesigner, value);
            }
        }

        public string BeforeHeader
        {
            get
            {
                return this._controlDesigner.BeforeHeader;
            }
            set
            {
                this.GetPropertyByName("BeforeHeader").SetValue(this._controlDesigner, value);
            }
        }

        public bool Enabled
        {
            get
            {
                return this._controlDesigner.Enabled;
            }
            set
            {
                this.GetPropertyByName("Enabled").SetValue(this._controlDesigner, value);
            }
        }

        public string[] ScriptFiles
        {
            get
            {
                return this._controlDesigner.ScriptFiles;
            }
            set
            {
                this.GetPropertyByName("ScriptFiles").SetValue(this._controlDesigner, value);
            }
        }

        public string[] StyleSheets
        {
            get
            {
                return this._controlDesigner.StyleSheets;
            }
            set
            {
                this.GetPropertyByName("StyleSheets").SetValue(this._controlDesigner, value);
            }
        }
    }
}

